package com.levy.contronller.lamdaTest;

import java.util.function.Supplier;

public class SupplierTest {


    public static void main(String[] args) {
        SupplierTest supplierTest = new SupplierTest();


        //可应用于工厂  不接受参数 直接返回一个对象
        Supplier<String> supplier = () -> "xxx";
        System.out.println(supplier.get());

        System.out.println("--------------------------");
        Supplier<Student> s1 = () -> new Student();
        System.out.println(s1.get());

        System.out.println("--------------------------");
        Supplier<Student> s2 = Student::new;
        System.out.println(s2.get());


    }


}

class Student {
    private String name = "zhangsan";
    private int age = 20;

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("{");
        sb.append("\"name\":\"")
                .append(name).append('\"');
        sb.append(",\"age\":")
                .append(age);
        sb.append('}');
        return sb.toString();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public Student() {

    }
}
